package com.liujit.gateway.config;

import com.liujit.common.constants.HeaderConstant;
import com.liujit.gateway.gray.GrayProperties;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.WebClient;

/**
 * @author: liujun
 * @date: 2021/6/15 3:51 下午
 * @description: WebClient配置
 */
@RequiredArgsConstructor
@Configuration
@EnableConfigurationProperties(GrayProperties.class)
public class WebClientConfig {

    private final GrayProperties grayProperties;

    @Bean
    @LoadBalanced
    public WebClient.Builder webClientBuilder() {
        return WebClient.builder().defaultHeader(HeaderConstant.VERSION, grayProperties.getVersion());
    }

    @Bean
    public WebClient webClient(WebClient.Builder builder) {
        return builder.build();
    }
}
